@use '@material/ripple/mixins' as mdc-ripple;

@import '@material/density/functions.import';
@import '@material/theme/variables.import';
@import '@material/textfield/mixins.import';
@import '@material/textfield/variables.import';
@import '../mdc-helpers/mdc-helpers';
@import 'form-field-density';
@import 'form-field-subscript';
@import 'form-field-focus-overlay';
@import 'form-field-native-select';
@import 'mdc-text-field-theme-variable-refresh';

// Mixin that overwrites the default MDC text-field color styles to be based on
// the given theme palette. The MDC text-field is styled using `primary` by default.
@mixin _mdc-text-field-color-styles($palette-name, $query: $mat-theme-styles-query) {
  $_mdc-text-field-focused-label-color: $mdc-text-field-focused-label-color;
  $mdc-text-field-focused-label-color: rgba(mdc-theme-prop-value($palette-name), 0.87) !global;

  @include mdc-text-field-caret-color($palette-name, $query);
  @include mdc-text-field-line-ripple-color($palette-name, $query);

  .mdc-text-field--focused {
    @include mdc-text-field-focused_($query);

  }
  .mdc-text-field--invalid {
    @include mdc-text-field-invalid_($query);
  }

  .mdc-text-field--outlined {
    @include mdc-text-field-focused-outline-color($palette-name, $query);
  }

  $mdc-text-field-focused-label-color: $_mdc-text-field-focused-label-color !global;
}

@mixin mat-mdc-form-field-color($config-or-theme) {
  $config: mat-get-color-config($config-or-theme);
  @include mat-using-mdc-theme($config) {
    @include _mdc-text-field-refresh-theme-variables() {
      @include mdc-text-field-without-ripple($query: $mat-theme-styles-query);
      @include mdc-floating-label-core-styles($query: $mat-theme-styles-query);
      @include mdc-notched-outline-core-styles($query: $mat-theme-styles-query);
      @include mdc-line-ripple-core-styles($query: $mat-theme-styles-query);
      @include _mat-mdc-form-field-subscript-color();
      @include _mat-mdc-form-field-focus-overlay-color();
      @include _mat-mdc-form-field-native-select-color($config);

      .mat-mdc-form-field.mat-accent {
        @include _mdc-text-field-color-styles(secondary);
      }

      .mat-mdc-form-field.mat-warn {
        @include _mdc-text-field-color-styles(error);
      }
    }
  }
}

@mixin mat-mdc-form-field-typography($config-or-theme) {
  $config: mat-get-typography-config($config-or-theme);
  @include mat-using-mdc-typography($config) {
    @include mdc-text-field-without-ripple($query: $mat-typography-styles-query);
    @include mdc-floating-label-core-styles($query: $mat-typography-styles-query);
    @include mdc-notched-outline-core-styles($query: $mat-typography-styles-query);
    @include mdc-line-ripple-core-styles($query: $mat-typography-styles-query);
    @include _mat-mdc-form-field-subscript-typography($config);

    .mat-mdc-form-field {
      @include mat-typography-level-to-styles($config, input);
    }
  }
}

@mixin mat-mdc-form-field-density($config-or-theme) {
  $density-scale: mat-get-density-config($config-or-theme);
  @include _mat-mdc-form-field-density($density-scale);
}

@mixin mat-mdc-form-field-theme($theme-or-color-config) {
  $theme: _mat-legacy-get-theme($theme-or-color-config);
  @include _mat-check-duplicate-theme-styles($theme, 'mat-mdc-form-field') {
    $color: mat-get-color-config($theme);
    $density: mat-get-density-config($theme);
    $typography: mat-get-typography-config($theme);

    @if $color != null {
      @include mat-mdc-form-field-color($color);
    }
    @if $density != null {
      @include mat-mdc-form-field-density($density);
    }
    @if $typography != null {
      @include mat-mdc-form-field-typography($typography);
    }
  }
}
